using Gateway.Common.Extensions;
using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class TenantConfiguration : AggregateRootEntityConfiguration<Tenant>
{
    public override void Configure(EntityTypeBuilder<Tenant> builder)
    {
        builder.ToTable(t => t.HasComment("租户表"));
        base.Configure(builder);
        builder.Property(x => x.TenantName).IsRequired().HasMaxLength(200).HasComment("租户名称");
        builder.Property(x => x.TenantAliasName).IsRequired().HasMaxLength(200).HasComment("租户别名");
        builder.Property(x => x.TenantCode).IsRequired().HasMaxLength(200).HasComment("租户编号");
        builder.Property(x => x.ContactName).IsRequired().HasMaxLength(200).HasComment("联系人名称");
        builder.Property(x => x.ContactPhone).IsRequired().HasMaxLength(200).HasComment("联系人电话");
        builder.Property(x => x.ExpireTime).IsRequired().HasMaxLength(19).HasComment("过期时间")
            .HasConversion(x => x.ToStandardString(), s => s.ToDateTime());
        ;
        builder.Property(x => x.TenantAddress).HasMaxLength(2000).HasComment("租户地址");
        builder.Property(x => x.TenantMail).HasMaxLength(200).HasComment("租户邮箱");
        builder.Property(x => x.TenantDomain).IsRequired().HasMaxLength(500).HasComment("域名");
        builder.Property(x => x.LogoUrl).HasMaxLength(500).HasComment("logo 地址");
    }
}